package cn.njbdqn;

import java.util.List;
import java.util.Scanner;

public class Library {
    private List<Book>bookList;
    public List<Book> getBookList(){
        return bookList;
    }
    public void setBookList(List<Book>bookList){
        this.bookList=bookList;
    }

    /**
     * 判断id和name是否重复
     * @param book
     */
    public void addBook(Book book){
        if (book==null){
            return;
        }
        boolean flag=false;
        for (int i=0;i<bookList.size();i++){
            if (bookList.get(i).equals(book)){
                flag=true;
                break;
            }
        }
        if (!flag){
            this.bookList.add(book);
        }else{
            System.out.println("你输入的图书编号和名称已存在");
        }
    }


    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String result=null;
        Library library=new Library();
        Book book=null;
        do {
            System.out.println("效果：");
            System.out.println("请输入图书编号：");
            int bookId=sc.nextInt();
            System.out.println("请输入图书名称：");
            String Name=sc.next();
            System.out.println("请输入图书作者：");
            String Author=sc.next();
            System.out.println("请输入图书价格：");
            double Price=sc.nextDouble();
            book=new Book(bookId,Name,Author,Price);
            library.addBook(book);
            System.out.println("是否继续输入");
            result=sc.next();
        }while (result!="n");
        System.out.println("查看图书");
        for (Book b:library.getBookList()){
            System.out.println(b);
        }

    }
}
